package com.tanhua.server.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.tanhua.common.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserService {
    @Autowired
    private RSAService rsaService;

    //校验token
    public Long checkToken(String token) {
        Map<String, Object> map = JwtUtils.checkToken(token, rsaService.getPublicKeyStr());
        //map为空返回null
        if (CollUtil.isEmpty(map)) {
            return null;
        }
        //不为空返回userId
        return Convert.toLong(map.get("userId"));
    }
}
